package org.chiv.gof.factory;

public class SimpleFactory {

    //抽象接口
    interface Product{
        void show();
    }

    //子类A实现接口
    class ProductA implements Product{

        public void show() {
            System.out.println("这里是ProductA");
        }
    }
    //子类B实现接口
    class ProductB implements Product{

        public void show() {
            System.out.println("这里是ProductB");
        }
    }

    /**
     * 根据需要生成不同的bean
     *
     * @param type
     * @return
     */
    public Product getProduct(int type){
        Product product = null;
        if(type == 0){
            product = new ProductA();
        }else if(type == 1){
            product = new ProductB();
        }
        return product;
    }
    public static void main(String[] args) {
        SimpleFactory simpleFactory = new SimpleFactory();
        //生产productA
        Product product = simpleFactory.getProduct(0);
        product.show();
    }
}
